1. Field of the Invention
The present invention relates computer graphics. More specifically, one or more embodiments of the present invention relate to a unified shader.
Portions of the disclosure of this patent document contain material that is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure as it appears in the Patent and Trademark Office file or records, but otherwise reserves all copyright rights whatsoever.
2. Background Art
Computer systems are often used to generate and display graphics on an output device such as a monitor. Display images are made up of thousands of tiny dots, where each dot is one of thousands or millions of colors. These dots are known as picture elements, or “pixels”. Each pixel has multiple attributes associated with it, including a color and a texture. A shader is used to perform arithmetic and logical operations on all of the attributes of the pixel to achieve one value that is used when the pixel is output. Typically graphics systems use separate shaders for texture and color. Separate shaders make their use difficult and expensive. This problem can be understood by reviewing the way that graphics systems process data.
Each pixel has a color, with the color of each pixel being represented by a number value stored in the computer system. A three dimensional display image, although displayed using a two dimensional array of pixels, may in fact be created by rendering of a plurality of graphical objects. Examples of graphical objects include points, lines, polygons, and three dimensional solid objects. Points, lines, and polygons represent rendering “primitives” which are the basis for most rendering instructions. More complex structures, such as three dimensional objects, are formed from a combination or mesh of such primitives. To display a particular scene, the visible primitives associated with the scene are drawn individually by determining those pixels that fall within the edges of the primitive, and obtaining the attributes of the primitive that correspond to each of those pixels. The obtained attributes are used to determine the displayed color values of applicable pixels.
Sometimes, a three dimensional display image is formed from overlapping primitives or surfaces. A blending function based on an opacity value associated with each pixel of each primitive is used to blend the colors of overlapping surfaces or layers when the top surface is not completely opaque. The final displayed color of an individual pixel may thus be a blend of colors from multiple surfaces or layers.
In some cases, graphical data is rendered by executing instructions from an application that is drawing data to a display. During image rendering, three dimensional data is processed into a two dimensional image suitable for display. The three dimensional image data represents attributes such as color, opacity, texture, depth, and perspective information. The draw commands from a program drawing to the display may include, for example, X and Y coordinates for the vertices of the primitive, as well as some attribute parameters for the primitive (color and depth or “Z” data), and a drawing command. The execution of drawing commands to generate a display image is known as graphics processing.
Shaders
A shader performs the processing in the graphics pipeline for each pixel. Namely, a shader performs all of the arithmetic and logical operations on all of the attributes of the pixel to combine them and generate a single color value. The single attribute value is placed in a computer's frame buffer and is used when the pixel is output to a display device. Typically graphics systems divide shaders into a texture address unit and a pixel shader. A texture address unit handles texture address calculations. A pixel shader handles color value calculations.
Historically, two types of categories fall into the shader. A first category is the processing of color, which may include processing Z, all of the source attributes having come from interpolation across primitives or a texturing operation. A second category is the operations performed on the texture coordinates themselves. Some prior systems that operate on texture coordinates place all textures into a single pipeline or process multiple texture images in parallel across multiple pipelines. One scheme with a single pipeline uses indirect texturing. Indirect texturing performs texture operations on a pixel (or a number of pixels in parallel) and then uses the texture value to alter the texture coordinates of the pixel if necessary.
Indirect Texturing
Indirect texturing may be used to perform bump mapping, among other things. Bump mapping uses a first texture image with a first set of texture coordinates and a second texture image with a second set of texture coordinates. The first texture image represents a displacement (or bumpiness) that when combined with the texture coordinates of the second texture image displace the texture coordinates which are then sent back through the pipeline. This produces a textured surface that is not totally a smooth light surface, but rather a more textured, bumpy surface, which is more realistic. Another scheme uses a loopback facility to pass the output of the pipeline back to the input of the pipeline to enhance bump mapping operations.
Still, however, conventional shaders are separated into two classes which perform different shading computations. Shading computations performed on colors are typically low precision, 8 bits for instance. Shading computations performed on texture coordinates are typically of higher precision and range because they are addresses into images and must address the image at a sub-texel resolution. So, typically there is a 12 bit number needed for the coordinate of the texture address plus additional bits, three or four for instance, to identify the sub-texel sample location to avoid aliasing effects. Moreover, these bits require an even higher number of bits to achieve accuracy in the range of 15 to 16 bits. Thus, substantially higher precision is needed in a texture coordinate configured shader than in a color shader (twice the precision or more is typical).
For these reasons, color shaders are used for general applications of color while texture coordinate shaders have been limited to only performing high precision bump mapping displacement algorithms. Due to the differing number of bit precisions for the two shaders, each shader uses its own instruction sets, which constrains the generality, flexibility, and overall usefulness of shading algorithms. Moreover, the underlying drivers and computer hardware involved in shading must know whether it is dealing with a color or a texture coordinate, which is disadvantageous.
Another problem associated with multiple, limited shaders is in the structures that must be implemented to perform the shading necessary to render an image. In particular, displacement mapping requires very large structures to hold pixels that are to be operated upon. These structures typically service the pixels in a first-in, first-out manner (FIFO). The FIFOs using bump mapping become huge and inefficient and a large buffer must also be used to store the interpolated results that are to be operated on. The buffer is typically a register and there is a cost associated with synchronizing data between a separate FIFO and register.